package com.jeesite.modules.pt.web;

import java.util.List;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import com.jeesite.modules.ic.entity.IcUser;
import com.jeesite.modules.ic.service.IcUserService;
import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.ModelAttribute;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import com.jeesite.common.config.Global;
import com.jeesite.common.entity.Page;
import com.jeesite.common.web.BaseController;
import com.jeesite.modules.pt.entity.PtYijian;
import com.jeesite.modules.pt.service.PtYijianService;

/**
 * 意见反馈Controller
 * @author 李寒冰
 * @version 2025-05-16
 */
@Controller
@RequestMapping(value = "${adminPath}/pt/ptYijian")
public class PtYijianController extends BaseController {

	@Autowired
	private PtYijianService ptYijianService;
    @Autowired
    private IcUserService icUserService;

	/**
	 * 获取数据
	 */
	@ModelAttribute
	public PtYijian get(String id, boolean isNewRecord) {
		return ptYijianService.get(id, isNewRecord);
	}
	
	/**
	 * 查询列表
	 */
	@RequiresPermissions("pt:ptYijian:view")
	@RequestMapping(value = {"list", ""})
	public String list(PtYijian ptYijian, Model model) {
		model.addAttribute("ptYijian", ptYijian);
		return "modules/pt/ptYijianList";
	}
	
	/**
	 * 查询列表数据
	 */
	@RequiresPermissions("pt:ptYijian:view")
	@RequestMapping(value = "listData")
	@ResponseBody
	public Page<PtYijian> listData(PtYijian ptYijian, HttpServletRequest request, HttpServletResponse response) {
		ptYijian.setPage(new Page<>(request, response));
		Page<PtYijian> page = ptYijianService.findPage(ptYijian);
		List<PtYijian> list = page.getList();
		for (PtYijian ptYijian1 : list) {
			String userId = ptYijian1.getUserId();
			IcUser icUser = icUserService.get(userId);
			ptYijian1.setIcUser(icUser);
		}
		return page;
	}

	/**
	 * 查看编辑表单
	 */
	@RequiresPermissions("pt:ptYijian:view")
	@RequestMapping(value = "form")
	public String form(PtYijian ptYijian, Model model) {
		model.addAttribute("ptYijian", ptYijian);
		return "modules/pt/ptYijianForm";
	}

	/**
	 * 保存数据
	 */
	@RequiresPermissions("pt:ptYijian:edit")
	@PostMapping(value = "save")
	@ResponseBody
	public String save(@Validated PtYijian ptYijian) {
		ptYijianService.save(ptYijian);
		return renderResult(Global.TRUE, text("保存意见反馈成功！"));
	}
	
	/**
	 * 删除数据
	 */
	@RequiresPermissions("pt:ptYijian:edit")
	@RequestMapping(value = "delete")
	@ResponseBody
	public String delete(PtYijian ptYijian) {
		ptYijianService.delete(ptYijian);
		return renderResult(Global.TRUE, text("删除意见反馈成功！"));
	}
	
}